﻿/**  PACS v1.0
* YX_ImageFileInfo.cs
*
* 类 名： YX_ImageFileInfo
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/6/5 15:24:40   douwd    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Pacs.DAL
{
	/// <summary>
	/// 数据访问类:YX_ImageFileInfo
	/// </summary>
	public partial class YX_ImageFileInfo
	{
		public YX_ImageFileInfo()
		{}
		#region  Method


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from YX_ImageFileInfo");
			strSql.Append(" where ID='"+ID+"' ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Pacs.Model.YX_ImageFileInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ID != null)
			{
				strSql1.Append("ID,");
				strSql2.Append("'"+model.ID+"',");
			}
			if (model.XuLieID != null)
			{
				strSql1.Append("XuLieID,");
				strSql2.Append("'"+model.XuLieID+"',");
			}
			if (model.XuLiePaiXu != null)
			{
				strSql1.Append("XuLiePaiXu,");
				strSql2.Append(""+model.XuLiePaiXu+",");
			}
			if (model.DICMWenJianMing != null)
			{
				strSql1.Append("DICMWenJianMing,");
				strSql2.Append("'"+model.DICMWenJianMing+"',");
			}
			if (model.JianChaLeiXing != null)
			{
				strSql1.Append("JianChaLeiXing,");
				strSql2.Append("'"+model.JianChaLeiXing+"',");
			}
			if (model.JianChaLeiXingBianMa != null)
			{
				strSql1.Append("JianChaLeiXingBianMa,");
				strSql2.Append("'"+model.JianChaLeiXingBianMa+"',");
			}
			if (model.DICMWenJianLuJing != null)
			{
				strSql1.Append("DICMWenJianLuJing,");
				strSql2.Append("'"+model.DICMWenJianLuJing+"',");
			}
			if (model.DICMWenJianLeiXing != null)
			{
				strSql1.Append("DICMWenJianLeiXing,");
				strSql2.Append("'"+model.DICMWenJianLeiXing+"',");
			}
			if (model.DICMWenJianDaXiao != null)
			{
				strSql1.Append("DICMWenJianDaXiao,");
				strSql2.Append(""+model.DICMWenJianDaXiao+",");
			}
			if (model.WenJianMiaoShu != null)
			{
				strSql1.Append("WenJianMiaoShu,");
				strSql2.Append("'"+model.WenJianMiaoShu+"',");
			}
			if (model.TuPianWenJianMingCheng != null)
			{
				strSql1.Append("TuPianWenJianMingCheng,");
				strSql2.Append("'"+model.TuPianWenJianMingCheng+"',");
			}
			if (model.TuPianWenJianLuJing != null)
			{
				strSql1.Append("TuPianWenJianLuJing,");
				strSql2.Append("'"+model.TuPianWenJianLuJing+"',");
			}
			if (model.TuPianWenJianLeiXing != null)
			{
				strSql1.Append("TuPianWenJianLeiXing,");
				strSql2.Append("'"+model.TuPianWenJianLeiXing+"',");
			}
			if (model.SuoLueTuMingCheng != null)
			{
				strSql1.Append("SuoLueTuMingCheng,");
				strSql2.Append("'"+model.SuoLueTuMingCheng+"',");
			}
			if (model.SuoLueTuWenJianLeiXing != null)
			{
				strSql1.Append("SuoLueTuWenJianLeiXing,");
				strSql2.Append("'"+model.SuoLueTuWenJianLeiXing+"',");
			}
			if (model.SuoLueTuLuJing != null)
			{
				strSql1.Append("SuoLueTuLuJing,");
				strSql2.Append("'"+model.SuoLueTuLuJing+"',");
			}
			if (model.ChuangJianShiJian != null)
			{
				strSql1.Append("ChuangJianShiJian,");
				strSql2.Append("'"+model.ChuangJianShiJian+"',");
			}
			if (model.TuPianBianJi != null)
			{
				strSql1.Append("TuPianBianJi,");
				strSql2.Append("'"+model.TuPianBianJi+"',");
			}
			strSql.Append("insert into YX_ImageFileInfo(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Pacs.Model.YX_ImageFileInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update YX_ImageFileInfo set ");
			if (model.XuLieID != null)
			{
				strSql.Append("XuLieID='"+model.XuLieID+"',");
			}
			else
			{
				strSql.Append("XuLieID= null ,");
			}
			if (model.XuLiePaiXu != null)
			{
				strSql.Append("XuLiePaiXu="+model.XuLiePaiXu+",");
			}
			else
			{
				strSql.Append("XuLiePaiXu= null ,");
			}
			if (model.DICMWenJianMing != null)
			{
				strSql.Append("DICMWenJianMing='"+model.DICMWenJianMing+"',");
			}
			else
			{
				strSql.Append("DICMWenJianMing= null ,");
			}
			if (model.JianChaLeiXing != null)
			{
				strSql.Append("JianChaLeiXing='"+model.JianChaLeiXing+"',");
			}
			else
			{
				strSql.Append("JianChaLeiXing= null ,");
			}
			if (model.JianChaLeiXingBianMa != null)
			{
				strSql.Append("JianChaLeiXingBianMa='"+model.JianChaLeiXingBianMa+"',");
			}
			else
			{
				strSql.Append("JianChaLeiXingBianMa= null ,");
			}
			if (model.DICMWenJianLuJing != null)
			{
				strSql.Append("DICMWenJianLuJing='"+model.DICMWenJianLuJing+"',");
			}
			else
			{
				strSql.Append("DICMWenJianLuJing= null ,");
			}
			if (model.DICMWenJianLeiXing != null)
			{
				strSql.Append("DICMWenJianLeiXing='"+model.DICMWenJianLeiXing+"',");
			}
			else
			{
				strSql.Append("DICMWenJianLeiXing= null ,");
			}
			if (model.DICMWenJianDaXiao != null)
			{
				strSql.Append("DICMWenJianDaXiao="+model.DICMWenJianDaXiao+",");
			}
			else
			{
				strSql.Append("DICMWenJianDaXiao= null ,");
			}
			if (model.WenJianMiaoShu != null)
			{
				strSql.Append("WenJianMiaoShu='"+model.WenJianMiaoShu+"',");
			}
			else
			{
				strSql.Append("WenJianMiaoShu= null ,");
			}
			if (model.TuPianWenJianMingCheng != null)
			{
				strSql.Append("TuPianWenJianMingCheng='"+model.TuPianWenJianMingCheng+"',");
			}
			else
			{
				strSql.Append("TuPianWenJianMingCheng= null ,");
			}
			if (model.TuPianWenJianLuJing != null)
			{
				strSql.Append("TuPianWenJianLuJing='"+model.TuPianWenJianLuJing+"',");
			}
			else
			{
				strSql.Append("TuPianWenJianLuJing= null ,");
			}
			if (model.TuPianWenJianLeiXing != null)
			{
				strSql.Append("TuPianWenJianLeiXing='"+model.TuPianWenJianLeiXing+"',");
			}
			else
			{
				strSql.Append("TuPianWenJianLeiXing= null ,");
			}
			if (model.SuoLueTuMingCheng != null)
			{
				strSql.Append("SuoLueTuMingCheng='"+model.SuoLueTuMingCheng+"',");
			}
			else
			{
				strSql.Append("SuoLueTuMingCheng= null ,");
			}
			if (model.SuoLueTuWenJianLeiXing != null)
			{
				strSql.Append("SuoLueTuWenJianLeiXing='"+model.SuoLueTuWenJianLeiXing+"',");
			}
			else
			{
				strSql.Append("SuoLueTuWenJianLeiXing= null ,");
			}
			if (model.SuoLueTuLuJing != null)
			{
				strSql.Append("SuoLueTuLuJing='"+model.SuoLueTuLuJing+"',");
			}
			else
			{
				strSql.Append("SuoLueTuLuJing= null ,");
			}
			if (model.ChuangJianShiJian != null)
			{
				strSql.Append("ChuangJianShiJian='"+model.ChuangJianShiJian+"',");
			}
			else
			{
				strSql.Append("ChuangJianShiJian= null ,");
			}
			if (model.TuPianBianJi != null)
			{
				strSql.Append("TuPianBianJi='"+model.TuPianBianJi+"',");
			}
			else
			{
				strSql.Append("TuPianBianJi= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ID='"+ model.ID+"' ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from YX_ImageFileInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from YX_ImageFileInfo ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.YX_ImageFileInfo GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ID,XuLieID,XuLiePaiXu,DICMWenJianMing,JianChaLeiXing,JianChaLeiXingBianMa,DICMWenJianLuJing,DICMWenJianLeiXing,DICMWenJianDaXiao,WenJianMiaoShu,TuPianWenJianMingCheng,TuPianWenJianLuJing,TuPianWenJianLeiXing,SuoLueTuMingCheng,SuoLueTuWenJianLeiXing,SuoLueTuLuJing,ChuangJianShiJian,TuPianBianJi ");
			strSql.Append(" from YX_ImageFileInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			Pacs.Model.YX_ImageFileInfo model=new Pacs.Model.YX_ImageFileInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.YX_ImageFileInfo DataRowToModel(DataRow row)
		{
			Pacs.Model.YX_ImageFileInfo model=new Pacs.Model.YX_ImageFileInfo();
			if (row != null)
			{
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["XuLieID"]!=null)
				{
					model.XuLieID=row["XuLieID"].ToString();
				}
				if(row["XuLiePaiXu"]!=null && row["XuLiePaiXu"].ToString()!="")
				{
					model.XuLiePaiXu=int.Parse(row["XuLiePaiXu"].ToString());
				}
				if(row["DICMWenJianMing"]!=null)
				{
					model.DICMWenJianMing=row["DICMWenJianMing"].ToString();
				}
				if(row["JianChaLeiXing"]!=null)
				{
					model.JianChaLeiXing=row["JianChaLeiXing"].ToString();
				}
				if(row["JianChaLeiXingBianMa"]!=null)
				{
					model.JianChaLeiXingBianMa=row["JianChaLeiXingBianMa"].ToString();
				}
				if(row["DICMWenJianLuJing"]!=null)
				{
					model.DICMWenJianLuJing=row["DICMWenJianLuJing"].ToString();
				}
				if(row["DICMWenJianLeiXing"]!=null)
				{
					model.DICMWenJianLeiXing=row["DICMWenJianLeiXing"].ToString();
				}
				if(row["DICMWenJianDaXiao"]!=null && row["DICMWenJianDaXiao"].ToString()!="")
				{
					model.DICMWenJianDaXiao=int.Parse(row["DICMWenJianDaXiao"].ToString());
				}
				if(row["WenJianMiaoShu"]!=null)
				{
					model.WenJianMiaoShu=row["WenJianMiaoShu"].ToString();
				}
				if(row["TuPianWenJianMingCheng"]!=null)
				{
					model.TuPianWenJianMingCheng=row["TuPianWenJianMingCheng"].ToString();
				}
				if(row["TuPianWenJianLuJing"]!=null)
				{
					model.TuPianWenJianLuJing=row["TuPianWenJianLuJing"].ToString();
				}
				if(row["TuPianWenJianLeiXing"]!=null)
				{
					model.TuPianWenJianLeiXing=row["TuPianWenJianLeiXing"].ToString();
				}
				if(row["SuoLueTuMingCheng"]!=null)
				{
					model.SuoLueTuMingCheng=row["SuoLueTuMingCheng"].ToString();
				}
				if(row["SuoLueTuWenJianLeiXing"]!=null)
				{
					model.SuoLueTuWenJianLeiXing=row["SuoLueTuWenJianLeiXing"].ToString();
				}
				if(row["SuoLueTuLuJing"]!=null)
				{
					model.SuoLueTuLuJing=row["SuoLueTuLuJing"].ToString();
				}
				if(row["ChuangJianShiJian"]!=null && row["ChuangJianShiJian"].ToString()!="")
				{
					model.ChuangJianShiJian=DateTime.Parse(row["ChuangJianShiJian"].ToString());
				}
				if(row["TuPianBianJi"]!=null)
				{
					model.TuPianBianJi=row["TuPianBianJi"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,XuLieID,XuLiePaiXu,DICMWenJianMing,JianChaLeiXing,JianChaLeiXingBianMa,DICMWenJianLuJing,DICMWenJianLeiXing,DICMWenJianDaXiao,WenJianMiaoShu,TuPianWenJianMingCheng,TuPianWenJianLuJing,TuPianWenJianLeiXing,SuoLueTuMingCheng,SuoLueTuWenJianLeiXing,SuoLueTuLuJing,ChuangJianShiJian,TuPianBianJi ");
			strSql.Append(" FROM YX_ImageFileInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,XuLieID,XuLiePaiXu,DICMWenJianMing,JianChaLeiXing,JianChaLeiXingBianMa,DICMWenJianLuJing,DICMWenJianLeiXing,DICMWenJianDaXiao,WenJianMiaoShu,TuPianWenJianMingCheng,TuPianWenJianLuJing,TuPianWenJianLeiXing,SuoLueTuMingCheng,SuoLueTuWenJianLeiXing,SuoLueTuLuJing,ChuangJianShiJian,TuPianBianJi ");
			strSql.Append(" FROM YX_ImageFileInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM YX_ImageFileInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from YX_ImageFileInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

